package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManagerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin
@RequestMapping("/admin/product")
public class ManagerController {

    @Autowired
    private ManagerService managerService;

    @GetMapping("/getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> list =  managerService.getCategory1();
        return Result.ok(list);
    }

    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id){
        List<BaseCategory2> list = managerService.getCategory2(category1Id);
        return Result.ok(list);
    }

    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id){
        List<BaseCategory3> list = managerService.getCategory3(category2Id);
        return Result.ok(list);
    }

    //根据一二三级分类ID 查询平台属性及属性值集合
    //返回值 Result  data  = List<BaseAttrInfo> 平台属性集合
    // BaseAttrInfo 平台属性对象 里面有平台属性值集合
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(
            @PathVariable Long category1Id,
            @PathVariable Long category2Id,
            @PathVariable Long category3Id
    ){
        List<BaseAttrInfo> baseAttrInfoList = managerService.attrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(baseAttrInfoList);
    }

    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        managerService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable Integer page, @PathVariable Integer limit){
        IPage<BaseTrademark> baseTrademarkIPage =  managerService.baseTrademark(page, limit);
        return Result.ok(baseTrademarkIPage);
    }

    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        List<BaseAttrValue> list = managerService.getAttrValueList(attrId);
        return Result.ok(list);
    }

    @GetMapping("/baseTrademark/get/{id}")
    public Result getBaseTrademark(@PathVariable Long id){
        BaseTrademark baseTrademark = managerService.getBaseTrademark(id);
        return Result.ok(baseTrademark);
    }

    @PutMapping("/baseTrademark/update")
    public Result baseTrademarkUpdate(@RequestBody BaseTrademark trademark){
        managerService.baseTrademarkUpdate(trademark);
        return Result.ok();
    }

    @GetMapping("/{page}/{limit}")
    public Result spuList(@PathVariable Integer page, @PathVariable Integer limit, Long category3Id){
        IPage<SpuInfo> spuInfoIPage = managerService.spuList(page, limit, category3Id);
        return Result.ok(spuInfoIPage);
    }

    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = managerService.getTrademarkList();
        return Result.ok(list);
    }

    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> list = managerService.baseSaleAttrList();
        return Result.ok(list);
    }

    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        managerService.saveSpuInfo(spuInfo);
        return Result.ok();
    }

    @GetMapping("/spuImageList/{spuId}")
    public Result spuImageList(@PathVariable Long spuId){
        List<SpuImage> list = managerService.spuImageList(spuId);
        return Result.ok(list);
    }

    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result spuSaleAttrList(@PathVariable Long spuId){
        List<SpuSaleAttr> list = managerService.spuSaleAttrList(spuId);
        return Result.ok(list);
    }

    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        managerService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    @GetMapping("/list/{page}/{limit}")
    public Result list(@PathVariable Integer page, @PathVariable Integer limit){
        IPage<SkuInfo> skuInfoIPage = managerService.list(page, limit);
        return Result.ok(skuInfoIPage);
    }

    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        managerService.onSale(skuId);
        return Result.ok();
    }

    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        managerService.cancelSale(skuId);
        return Result.ok();
    }

}
